package com.ea.config;

import com.ea.holder.RequestHandlerInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author NAME-L
 * @Description TODO
 * @className InterceptorConfig
 * @date 2023-01-15 20:31:49
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private RequestHandlerInterceptor requestHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        registry.addInterceptor(requestHandlerInterceptor)
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/electric/front/user/loginIn")				//添加不拦截的请求路径
                .excludePathPatterns("/electric/front/user/register")				//添加不拦截的请求路径
                .excludePathPatterns("/electric/back/admin/loginIn")
                .excludePathPatterns("/electric/back/admin/create")
                .excludePathPatterns("/electric/front/store/**")
                .excludePathPatterns("/electric/file/**")
                .excludePathPatterns("/electric/common/**")
                .addPathPatterns("/**");        //添加需要拦截的路径

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //addResourceHandler：指的是对外暴露的访问路径
        //addResourceLocations：指的是内部文件放置的目录
        registry.addResourceHandler("/electric/file/**")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("file:E:/studyProject/electric_shop/electric_appliance/admin/src/main/resources/static");
    }
}
